package com.heima.wemedia.config;

import com.heima.model.common.constants.message.PublishArticleConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Slf4j
@Configuration
public class DeclarePubArticleRabbitConfig {

    /**
     * 实例化延时交换机
     * @return
     */
    @Bean
    public DirectExchange delayExchange(){
        return ExchangeBuilder.directExchange(PublishArticleConstants.DELAY_DIRECT_EXCHANGE)
                .durable(true).delayed().build();
    }

    @Bean
    public Queue queue(){
        return new Queue(PublishArticleConstants.PUBLISH_ARTICLE_QUEUE);
    }

    @Bean
    public Binding binding(){
        return BindingBuilder.bind(queue()).to(delayExchange()).with(PublishArticleConstants.PUBLISH_ARTICLE_ROUTE_KEY);
    }
}
